package com.rgs.ssm.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @create 2021-02-16 22:35
 * 时间转换的工具类
 **/
public class DateUtils {

    /**
     * 时间转成字符串
     * @param date
     * @param patt
     * @return
     */
    public static String dateToString(Date date, String patt){
        SimpleDateFormat sdf = new SimpleDateFormat(patt);
        String format = sdf.format(date);
        return format;
    }

    /**
     * 字符串转成日期格式
     * @param str
     * @param patt
     * @return
     */
    public static Date stringToDate(String str, String patt) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(patt);
        Date parse = sdf.parse(str);
        return parse;
    }
}
